from PyQt5.QtWidgets import QWidget,  QLabel, QHBoxLayout, QVBoxLayout, QPushButton, QTextEdit, QTableWidget, QTableWidgetItem, QCheckBox, QGridLayout, QApplication, QHeaderView,QLineEdit
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont, QPixmap
import sys
import urllib.request as urllib2
import http.client
import json
import threading
from MessageView import TransactionDetial
import sys
import os
class LoginFrom(QWidget):
    def __init__(self):
        super(LoginFrom, self).__init__()

        self.initUI()

    def initUI(self):
        self.setWindowTitle("登录")
        self.setAutoFillBackground(False)
        self.setWindowFlags(Qt.WindowMinimizeButtonHint| Qt.WindowCloseButtonHint|Qt.MSWindowsFixedSizeDialogHint)
        self.setGeometry(500,200,300,300)
        #窗口垂直布局
        vbox = QVBoxLayout()
        vbox.setSpacing(0)
        self.setLayout(vbox)
        Lab = QLabel("用户登录")
        Lab.setFixedHeight(20)
        Lab.adjustSize()
        Lab.setFont(QFont("Roman times", 15, QFont.Bold))  # 设置字体大小和加粗
        vbox.addWidget(Lab)

        self.CenterWidget = QWidget()
        centerHbox = QHBoxLayout()
        self.CenterWidget.setLayout(centerHbox)

        self.BottomWidget = QWidget()
        bottomHbox = QHBoxLayout()
        bottomHbox.setSpacing(20)
        self.BottomWidget.setLayout(bottomHbox)


        vbox.addWidget(self.CenterWidget)
        # vbox.addWidget(self.NextWidget)
        vbox.addWidget(self.BottomWidget)

        hboxLayout = QHBoxLayout()
        self.setLayout(hboxLayout)
        self.leftWidget = QWidget()
        self.leftWidget.setFixedWidth(120)
        self.leftWidget.setStyleSheet(
            "QWidget{ background:transparent;color: black;border: 0px solid white;}")
        # 设置布局
        leftWidgetLayout = QVBoxLayout()
        leftWidgetLayout.setSpacing(5)
        self.leftWidget.setLayout(leftWidgetLayout)
        label = ["账  户", "密  码", "安全码", "激活码"]

        lab4 = QLabel(label[2])
        lab4.setFixedHeight(40)
        lab4.setFixedWidth(100)
        lab4.setStyleSheet(
            "QWidget{ background:transparent;color: black;font-size:25px;border: 0px solid white;font-weight: bold;border-width: 0px;border-color: #141529;border-style: solid;border-radius:4;}")
        leftWidgetLayout.addWidget(lab4)

        lab3 = QLabel(label[0])
        lab3.setFixedHeight(40)
        lab3.setFixedWidth(100)
        lab3.setStyleSheet(
            "QWidget{ background:transparent;color: black;font-size:25px;border: 0px solid white;font-weight: bold;border-width: 0px;border-color: #141529;border-style: solid;border-radius:4;}")
        leftWidgetLayout.addWidget(lab3)

        lab1 = QLabel(label[1])
        lab1.setFixedHeight(40)
        lab1.setFixedWidth(100)
        lab1.setStyleSheet(
            "QWidget{ background:transparent;color: black;font-size:25px;border: 0px solid white;font-weight: bold;border-width: 0px;border-color: #141529;border-style: solid;border-radius:4;}")
        leftWidgetLayout.addWidget(lab1)

        lab2 = QLabel(label[3])
        lab2.setStyleSheet(
            "QWidget{ background:transparent;color: black;font-size:25px;border: 0px solid white;font-weight: bold;border-width: 0px;border-color: #141529;border-style: solid;border-radius:4;}")
        lab2.setFixedHeight(40)
        lab2.setFixedWidth(100)
        leftWidgetLayout.addWidget(lab2)

        yzm = QLabel()
        yzm.setStyleSheet(
            "QWidget{ background:transparent;color: black;font-size:25px;border: 0px solid white;font-weight: bold;border-width: 0px;border-color: #141529;border-style: solid;border-radius:4;}")
        yzm.setFixedHeight(40)
        yzm.setFixedWidth(100)
        img = QPixmap('abc.jpg').scaled(yzm.width(), yzm.height())
        yzm.setPixmap(img)
        leftWidgetLayout.addWidget(yzm)

        Cancle_btn=QPushButton("取消")
        Cancle_btn.setFixedWidth(80)
        Cancle_btn.setStyleSheet(
            "QWidget{ background:#169bef;color: white;font-size:25px;border: 1px solid white;font-weight: bold;border-width: 0px;border-color: #141529;border-style: solid;border-radius:4;}")
        bottomHbox.addWidget(Cancle_btn)
        Cancle_btn.clicked.connect(self.Clicked)
        # 右布局

        self.RightWidget = QWidget()
        self.RightWidget.setFixedWidth(240)
        self.RightWidget.setStyleSheet(
            "QWidget{ background:transparent;color: black;border: 0px solid white;}")
        RightWidgetLayout = QVBoxLayout()
        RightWidgetLayout.setSpacing(5)
        self.RightWidget.setLayout(RightWidgetLayout)


        self.an_qm = QTextEdit()
        self.an_qm.setFixedHeight(40)
        self.an_qm.setFixedWidth(200)
        self.an_qm.setStyleSheet(
            "QWidget{ background:white;color: black;font-size:25px;border: 1px solid white;font-weight: bold;border-width: 1px;border-color: #141529;border-style: solid;border-radius:4;}")
        self.an_qm.setEnabled(True)
        RightWidgetLayout.addWidget(self.an_qm)


        self.user = QTextEdit()
        self.user.setFixedHeight(40)
        self.user.setFixedWidth(200)
        self.user.setStyleSheet(
            "QWidget{ background:white;color: black;font-size:25px;border: 1px solid white;font-weight: bold;border-width: 1px;border-color: #141529;border-style: solid;border-radius:4;}")
        self.user.setEnabled(True)
        RightWidgetLayout.addWidget(self.user)

        self.pwd = QLineEdit()
        self.pwd.setEchoMode(QLineEdit.Password)
        self.pwd.setFixedHeight(40)
        self.pwd.setFixedWidth(200)
        self.pwd.setStyleSheet(
            "QWidget{ background:white;color: black;font-size:25px;border: 1px solid white;font-weight: bold;border-width: 1px;border-color: #141529;border-style: solid;border-radius:4;}")
        self.pwd.setEnabled(True)
        RightWidgetLayout.addWidget(self.pwd)

        self.ji_hm = QLineEdit()

        self.ji_hm.setMaxLength(6)
        self.ji_hm.setFixedHeight(40)
        self.ji_hm.setFixedWidth(200)
        self.ji_hm.setStyleSheet(
            "QWidget{ background:white;color: black;font-size:25px;border: 1px solid white;font-weight: bold;border-width: 1px;border-color: #141529;border-style: solid;border-radius:4;}")
        self.ji_hm.setEnabled(True)
        RightWidgetLayout.addWidget(self.ji_hm)

        OK_btn = QPushButton("登录")
        OK_btn.setFixedWidth(80)
        OK_btn.setStyleSheet(
            "QWidget{ background:#169bef;color: white;font-size:25px;border: 1px solid white;font-weight: bold;border-width: 0px;border-color: #141529;border-style: solid;border-radius:4;}")

        bottomHbox.addWidget(OK_btn)
        OK_btn.clicked.connect(self.Clicked)
        centerHbox.addWidget(self.leftWidget)
        centerHbox.addWidget(self.RightWidget)

    def Clicked(self):
        try:
            who = self.sender()
            if who is not None:
                name = who.text()
                if name == "登录":
                    print('登入')
                    print(self.ji_hm.text())
                    print(self.pwd.text())
                    print(self.an_qm.toPlainText())
                    print(self.user.toPlainText())
                    self.password = self.pwd.text()  # 密码
                    self.user_name = self.user.toPlainText()  # 用户名
                    self.anQm = self.an_qm.toPlainText()  # 安全码
                    self.ji_hm_str = self.ji_hm.text()  # 激活码

                    # self.Transactionmonitoring = TransactionDetial(self.anQm, self.user_name,self.password, self.ji_hm_str )  # 启动主业
                    self.Transactionmonitoring = TransactionDetial('381492', 'abc789', 'zxcv1212', self.ji_hm_str )  # 启动主业
                    self.close()
                    # self.CommitData()
                    # self.JudgeInfo()
                elif name =="取消":
                    self.ji_hm.clear()
                    self.pwd.clear()
                    self.an_qm.clear()
                    self.user.clear()

        except Exception as error:
            print(error)

class MyThread(threading.Thread):
    def __init__(self, n):
        super(MyThread, self).__init__()  # 重构run函数必须要写

    def run(self):
        print("ss")
def main():
    try:
        if hasattr(sys, '_MEIPASS'):
            os.chdir(sys._MEIPASS)
        app = QApplication(sys.argv)
        ex = LoginFrom()
        app.installEventFilter(ex)
        ex.show()
        sys.exit(app.exec_())
    except Exception as error:
        print(error)


if __name__ == '__main__':
   main()


